<?php
$this->title = 'Rest API用户';
?>
<section class="content" ng-app="myApp">
  <div class="row">
    <div class="col-xs-12">
      <div class="nav-tabs-custom">
        <?php include 'nav.php';?>
        <div class="tab-content">
          <!-- Rest API用户-->
          <div class="tab-pane active" id="user">
            <section ng-controller="restApiCtrl" ng-cloak>

              <h4 class="seting-header" style="margin-bottom: -1px;">
                <i class="fa fa-user"></i>
                Rest API用户
              </h4>
              <!-- 用户列表 -->
              <div class="userList" ng-if="!addUserData.show">
                <div class="margin" style="background-color: #fbf6e1;color: #c09853;padding: 15px;border-radius: 5px;">
                  <b><i class="fa fa-exclamation-triangle"></i>请注意：</b><span>Rest
                    API用户为第三方平台通过API和本平台实现交互的用户。通过下面创建用户会自动生成ClientID和ClientSecret。</span>
                </div>
                <div>
                  <button type="button" class="btn btn-primary" ng-click="createUser()">创建用户</button>
                  <div class="input_box"
                    style='display:inline-block;width:400px;vertical-align: middle;margin-left:20px;'>
                    <div class="input-group">
                      <input type="text" ng-model="search.data" class="form-control" placeholder="输入用户名、ClientID或备注"
                        aria-describedby="basic-addon1">
                      <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="getPage(1)">搜索</button>
                      </span>
                    </div>
                  </div>
                </div>
                <div class="row" style="margin-top:20px;">
                  <div class="col-sm-12" class="table-responsive">
                    <table class="table table-hover" ng-show="pages.data.length>0"
                      style="border-bottom: 1px solid #f4f4f4;">
                      <tr>
                        <th>用户名</th>
                        <th>ClientID</th>
                        <th>备注</th>
                        <th>最后登录时间</th>
                        <th>创建时间</th>
                        <th>操作</th>
                      </tr>

                      <tr style="cursor: pointer;" ng-repeat="item in pages.data">
                        <td ng-bind="item.username"></td>
                        <td ng-bind="item.client_id"></td>
                        <td ng-bind="item.desc"></td>
                        <td style="width:200px" ng-bind="item.updated_at*1000 | date:'yyyy-MM-dd HH:mm'"></td>
                        <td style="width:200px" ng-bind="item.created_at*1000 | date:'yyyy-MM-dd HH:mm'"></td>
                        <td style="width:250px">
                          <span class="text-primary" ng-click="popPower(item);$event.stopPropagation();" >修改权限</span>
                          <span class="text-primary" ng-click="downloadLog(item);$event.stopPropagation();"
                          style=" middle;margin-left:10px;">审计日志</span>
                          <span class="text-primary" ng-click="del(item);$event.stopPropagation();"
                            style=" middle;margin-left:10px;">删除</span>
                          <!-- <button class="btn btn-xs btn-default" ng-click="del(item);$event.stopPropagation();"><i
                            class="fa fa-trash-o" data-toggle="tooltip" title="删除用户"></i></button>
                        <button class="btn btn-xs btn-default"
                          ng-click="resetPassword(item);$event.stopPropagation();"><i class="fa fa-edit"
                            data-toggle="tooltip" title="重置密码"></i></button> -->
                        </td>
                      </tr>
                    </table>
                  </div>
                </div>
                <div class="row">
                  <div class="col-sm-12" style="min-height: 20px;">
                    <span>共<span ng-bind="pages.count"></span>个用户</span>
                    <ul class="pagination pagination-sm no-margin pull-right" ng-if="pages.count>0">
                      <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow-1)"
                          ng-if="pages.pageNow>1">上一页</a></li>
                      <li><a href="javascript:void(0);" ng-click="getPage(1)" ng-if="pages.pageNow>1">1</a></li>
                      <li><a href="javascript:void(0);" ng-if="pages.pageNow>4">...</a></li>

                      <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow-2)" ng-bind="pages.pageNow-2"
                          ng-if="pages.pageNow>3"></a></li>
                      <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow-1)" ng-bind="pages.pageNow-1"
                          ng-if="pages.pageNow>2"></a></li>

                      <li class="active"><a href="javascript:void(0);" ng-bind="pages.pageNow"></a></li>

                      <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow+1)" ng-bind="pages.pageNow+1"
                          ng-if="pages.pageNow<pages.maxPage-1"></a></li>
                      <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow+2)" ng-bind="pages.pageNow+2"
                          ng-if="pages.pageNow<pages.maxPage-2"></a></li>


                      <li><a href="javascript:void(0);" ng-if="pages.pageNow<pages.maxPage-3">...</a></li>

                      <li><a href="javascript:void(0);" ng-click="getPage(pages.maxPage)" ng-bind="pages.maxPage"
                          ng-if="pages.pageNow<pages.maxPage"></a></li>
                      <li><a href="javascript:void(0);" ng-click="getPage(pages.pageNow+1)"
                          ng-if="pages.pageNow<pages.maxPage">下一页</a></li>
                    </ul>
                  </div>
                </div>
              </div>
              <!-- 创建用户 -->
              <div class="createUser" ng-if="addUserData.show && !addUserData.createInfo">
                <div style="width:600px;margin-top:20px;">
                  <form>
                    <div class="form-group">
                      <label for="exampleInputEmail1">
                        用户名
                        <span style="color:red">*</span>
                      </label>
                      <input type="text" ng-model="addData.username"  class="form-control" id="exampleInputEmail1" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                      <label for="exampleInputPassword1">备注</label>
                      <textarea class="form-control" ng-model="addData.desc"  id="exampleInputPassword1" placeholder="填写备注对这个用户简单说明"
                        rows="2"></textarea>
                    </div>
                    <div class="form-group">
                      <table class="table table-hover" style="border-bottom: 1px solid #f4f4f4;">
                        <tr>
                          <th>权限策略命令</th>
                          <th>备注</th>
                          <th>选择权限</th>
                        </tr>

                        <tr style="cursor: pointer;" ng-repeat="item in cmdList">
                          <td ng-bind="item.name"></td>
                          <td ng-bind="item.remark"></td>
                          <td>
                            <input type="checkbox" ng-model="item.check" ng-checked="item.check">
                          </td>
                        </tr>
                      </table>
                    </div>
                    <div style="text-align:right">
                      <button style="margin-right:10px;" type="button" class="btn btn-primary"
                        ng-click="addUser()">确定</button>
                      <button type="button" class="btn btn-default" ng-click="backUserList()">返回</button>
                    </div>
                  </form>
                </div>

              </div>
              <!-- 生成用户信息 -->
              <div class="createInfo" ng-if="addUserData.createInfo">
                <div class="margin" style="background-color: #fbf6e1;color: #c09853;padding: 15px;border-radius: 5px;">
                  <b><i class="fa fa-exclamation-triangle"></i>请注意：</b>
                  <span>请在本页及时保存ClientSecret， 页面关闭后将无法再次获取信息。</span>
                </div>
                <table class="table table-hover" style="border-bottom: 1px solid #f4f4f4;">
                  <tr>
                    <th>用户名</th>
                    <th>备注</th>
                    <th>ClientID</th>
                    <th>ClientSecret</th>
                    <th>操作</th>
                  </tr>
                  <tr style="cursor: pointer;" ng-repeat="item in detailData">
                    <td ng-bind="item.username"></td>
                    <td ng-bind="item.desc"></td>
                    <td ng-bind="item.client_id"></td>
                    <td ng-bind="item.client_secret"></td>
                    <td>
                      <span class="text-primary" ng-click="DownloadCsv(item)" >下载CSV文件</span>
                      <span class="text-primary" ng-click="Copy(item)" style=" middle;margin-left:10px;">复制</span>
                    </td>
                  </tr>
                </table>
                <div>
                  <button type="button" class="btn btn-default" ng-click="backUserList()">返回</button>
                </div>
              </div>
              <!-- 权限弹窗 -->
              <div>
                <div style="display: none;" id="hideenBox">
                  <div id="power">
                     <table class="table table-hover" style="border-bottom: 1px solid #f4f4f4;">
                        <tr>
                          <th>权限策略命令</th>
                          <th>备注</th>
                          <th>选择权限</th>
                        </tr>
                        <tr style="cursor: pointer;" ng-repeat="item in EditcmdList">
                          <td ng-bind="item.name"></td>
                          <td ng-bind="item.remark"></td>
                          <td>
                            <input type="checkbox" ng-model="item.check" ng-checked="item.check">
                          </td>
                        </tr>
                      </table>
                  </div>
                </div>
              </div>
            </section>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<script type="text/javascript" src="/js/controllers/restApi.js"></script>